#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define maxn 100005
int a, b;
bool nonum = false;
short S[maxn];
short num[maxn], res[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin >> a >> b;
    for (int i = 0; i < b; ++i)
    {
        char ch;
        cin >> ch;
        S[i] = ch - '0';
    }
    if (a >= 10)
        nonum = true;
    if (S[0] == 1)
        num[0] = a;
    else
    {
        num[0] = 1;
    }
    res[0] = num[0] % a;
    for (int i = 1; (i < b) && nonum == false; ++i)
    {
        if (S[i] == 0 && nonum == false) //前i位组成的数不是a的倍数
        {
            int tmp = 0, j;
            tmp = i >= 1 ? res[i - 1] : res[i];
            for (j = 0; j <= 9; ++j)
            {
                if ((tmp * 10 % a + j % a) % a != 0)
                {
                    num[i] = j;
                    break;
                }
            }
            res[i] = (tmp * 10 % a + j % a) % a;
            if (j == 9 && num[i] != j)
                nonum = true;
        }
        else if (S[i] == 1 && nonum == false)
        {
            int tmp = 0, j;
            tmp = i >= 1 ? res[i - 1] : res[i];
            for (j = 0; j <= 9; ++j)
            {
                if ((tmp * 10 % a + j % a) % a == 0)
                {
                    num[i] = j;
                    break;
                }
            }
            res[i] = (tmp * 10 % a + j % a) % a;
            if (j == 9 && num[i] != j)
                nonum = true;
        }
    }
    if (nonum == true)
        cout << -1;
    else
    {
        for (int i = 0; i < b; ++i)
            cout << num[i];
    }
    return 0;
}